package com.ruoyi.community.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.CpcBbsPostMapper;
import com.ruoyi.community.domain.CpcBbsPost;
import com.ruoyi.community.service.ICpcBbsPostService;

/**
 * 党员论坛帖Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-12-22
 */
@Service
public class CpcBbsPostServiceImpl implements ICpcBbsPostService 
{
    @Autowired
    private CpcBbsPostMapper cpcBbsPostMapper;

    /**
     * 查询党员论坛帖
     * 
     * @param postId 党员论坛帖ID
     * @return 党员论坛帖
     */
    @Override
    public CpcBbsPost selectCpcBbsPostById(String postId)
    {
        CpcBbsPost cpcBbsPost = cpcBbsPostMapper.selectCpcBbsPostById(postId);
        Integer viewNumber = cpcBbsPost.getViewNumber() + 1;
        cpcBbsPost.setViewNumber(viewNumber);
        updateCpcBbsPost(cpcBbsPost);
        return cpcBbsPost;
    }



    /**
     * 查询党员论坛帖列表
     * 
     * @param cpcBbsPost 党员论坛帖
     * @return 党员论坛帖
     */
    @Override
    public List<CpcBbsPost> selectCpcBbsPostList(CpcBbsPost cpcBbsPost)
    {
        return cpcBbsPostMapper.selectCpcBbsPostList(cpcBbsPost);
    }

    /**
     * 新增党员论坛帖
     * 
     * @param cpcBbsPost 党员论坛帖
     * @return 结果
     */
    @Override
    public Long insertCpcBbsPost(CpcBbsPost cpcBbsPost)
    {
        cpcBbsPost.setAuthorId(SecurityUtils.getUserID());
        cpcBbsPost.setAuthorName(SecurityUtils.getUsername());
        cpcBbsPost.setCommunityId(SecurityUtils.getCommunityId());
        cpcBbsPost.setViewNumber(0);
        cpcBbsPost.setCommentNumber(0);
        cpcBbsPostMapper.insertCpcBbsPost(cpcBbsPost);
        Long postId = cpcBbsPost.getPostId();
        return postId;
    }

    /**
     * 修改党员论坛帖
     * 
     * @param cpcBbsPost 党员论坛帖
     * @return 结果
     */
    @Override
    public int updateCpcBbsPost(CpcBbsPost cpcBbsPost)
    {
        return cpcBbsPostMapper.updateCpcBbsPost(cpcBbsPost);
    }

    /**
     * 批量删除党员论坛帖
     * 
     * @param postIds 需要删除的党员论坛帖ID
     * @return 结果
     */
    @Override
    public int deleteCpcBbsPostByIds(String[] postIds)
    {
        return cpcBbsPostMapper.deleteCpcBbsPostByIds(postIds);
    }

    /**
     * 删除党员论坛帖信息
     * 
     * @param postId 党员论坛帖ID
     * @return 结果
     */
    @Override
    public int deleteCpcBbsPostById(String postId)
    {
        return cpcBbsPostMapper.deleteCpcBbsPostById(postId);
    }
}
